package main

import (
	"context"
	"fmt"
	"github.com/apache/rocketmq-client-go"
	"github.com/apache/rocketmq-client-go/consumer"
	"github.com/apache/rocketmq-client-go/primitive"
	"os"
	"time"
)

func main ()  {
	c, _ := rocketmq.NewPushConsumer(
			consumer.WithGroupName("Consumber"),
			consumer.WithNsResovler(primitive.NewPassthroughResolver([]string{"120.79.162.72:9876"})),
		)
	err := c.Subscribe("BusInfo", consumer.MessageSelector{}, func(ctx context.Context, msgs ...*primitive.MessageExt) (consumer.ConsumeResult, error) {
		fmt.Print(len(msgs))
		for i := range msgs {
			fmt.Printf("subscribe callback: %v \n", msgs[i])
		}
		return consumer.ConsumeSuccess, nil
	})

	if err != nil {
		fmt.Print(err.Error())
	}

	err = c.Start()
	if err != nil {
		fmt.Print(err.Error())
		os.Exit(-1)
	}
	time.Sleep(time.Hour)
	err = c.Shutdown()
	if err != nil {
		fmt.Print("shutdown Consumer error: %s", err.Error())
	}
}
